home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / tctnt / psp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-27  |  1013 b   |  31 lines

  1. /* PSP.C: How to Get the Name of a Spawned Program's Parent */
  2.  
  3. #include <stdio.h>        // for putchar()
  4. #include <dos.h>          // for MK_FP
  5.  
  6. typedef unsigned SEG;
  7.  
  8. extern SEG _psp;
  9.  
  10. //*******************************************************************int main (void) {
  11.   SEG far * pspparent;    // Segment of parent PSP
  12.   SEG far * envparent;    // Segment of parent environment
  13.   char far *who;          // Char ptr to name of parent process
  14.  
  15.   // Get segment and environment of parent PSP
  16.   pspparent = (SEG far*)MK_FP (_psp, 0x16);
  17.   envparent = (SEG far*)MK_FP (*pspparent, 0x2C);
  18.  
  19.   // Initialize parent process name pointer
  20.   who = (char far*)MK_FP (*envparent, 0x00);
  21.  
  22.   // Find the end of the environment. The environment is terminated
  23.   // by two '\0' characters
  24.  
  25.   while (!((who [0] == '\0') && (who [1] == '\0'))) who++;
  26.  
  27.   // Point at the parent process name and display it. 
  28.   who += 4;
  29.   while (who [0] != '\0') putchar (*who++);
  30.   return 0; }  // end of main()
  31.